package algorithm_demo.leetcode;

/**
 * 11. 盛最多水的容器
 * <a href="https://leetcode.cn/problems/container-with-most-water/">https://leetcode.cn/problems/container-with-most-water/</a>
 * @author Api
 * @date 2023/5/9 0:36
 */
public class Problem_011_ContainerWithMostWater {
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length-1;
        int maxWater = 0;
        while(left < right){
            int max = Math.min(height[left], height[right])*(right-left);
            maxWater = Math.max(max, maxWater);
            if(height[left] > height[right]){
                right--;
            }else{
                left++;
            }
        }
        return maxWater;
    }
}
